using Game.Core;
using Game.Main.Model;
using Game.Main.View;
using Game.Manager;

namespace Game.Component
{
	public class DefibrillatorItem : HadRopeItem
	{
		private CharacterItem targetItem;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		public override void ResetState()
		{
			base.ResetState();
			InitPlaceItem();
		}

		protected override void LateUpdate()
		{
			base.LateUpdate();
			UpdatePutBackAnim();
		}

		protected override void OnItemCompTriggerEnter(ColliderData collData)
		{
			base.OnItemCompTriggerEnter(collData);
			if (collData.trigger.type == ItemComponentTrigger.Type.Body && collData.trigger.owner != null && collData.trigger.owner.itemData.scriptType == 1 && collData.trigger.owner.archiveData.layer != 9)
			{
				StopTargetItemShake(false);
				targetItem = (CharacterItem)collData.trigger.owner;
				((CharacterItem)collData.trigger.owner).PlayShakeAnim();
				base.PlayDragSound();
				base.PlayDragEffect(0.0004f);
				BaseItem itemByScriptType = Singleton<Scene>.Instance.GetItemByScriptType(106);
				if (itemByScriptType != null)
				{
					((DefibrillatorDisplayerItem)itemByScriptType).AddTarget(this);
				}
			}
		}

		protected override void OnItemCompTriggerExit(ColliderData collData)
		{
			base.OnItemCompTriggerExit(collData);
			if (targetItem != null && collData.trigger.type == ItemComponentTrigger.Type.Body && collData.trigger.owner.itemData.scriptType == 1 && collData.trigger.owner == targetItem)
			{
				StopTargetItemShake(true);
			}
		}

		private void StopTargetItemShake(bool stopDisplayer)
		{
			if (targetItem != null)
			{
				targetItem.StopShakeAnim();
				targetItem = null;
			}
			if (stopDisplayer)
			{
				StopDragSound();
				StopDragEffect();
				BaseItem itemByScriptType = Singleton<Scene>.Instance.GetItemByScriptType(106);
				if (itemByScriptType != null)
				{
					((DefibrillatorDisplayerItem)itemByScriptType).RemoveTarget(this);
				}
			}
		}

		protected override void PlayDragSound()
		{
		}

		protected override void PlayDragEffect(float z = -0.0004f)
		{
		}

		public override void TouchDown(TouchEventData touchEventData)
		{
			base.TouchDown(touchEventData);
			needBack = true;
			Singleton<AudioManager>.Instance.PlaySound("sound_defibrillator_take");
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			base.TouchUp(touchEventData);
			PutBackPlaceItem();
			StopTargetItemShake(true);
		}
	}
}
